/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import drawing from '@ohos.graphics.drawing';
import common2D from '@ohos.graphics.common2D';
import { StyleType, TestBase } from '../../pages/testbase';

export class PerformancePenSetColor extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen()
    let color: common2D.Color = { alpha: 255, red: 1, green: 255, blue: 1 };
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setColor(color);
    }
  }
}

export class PerformancePenGetColor extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getColor();
    }
  }
}

export class PerformancePenSetStrokeWidth extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setStrokeWidth(5);
    }
  }
}

export class PerformancePenSetAntiAlias extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setAntiAlias(true);
    }
  }
}

export class PerformancePenSetAlpha extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setAlpha(15);
    }
  }
}

export class PerformancePenGetAlpha extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getAlpha();
    }
  }
}

export class PerformancePenSetColorFilter extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let colorFilter = new drawing.ColorFilter();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setColorFilter(colorFilter)
    }
  }
}

export class PerformancePenGetColorFilter extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getColorFilter();
    }
  }
}

export class PerformancePenSetMaskFilter extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let maskFilter = new drawing.MaskFilter();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setMaskFilter(maskFilter);
    }
  }
}

export class PerformancePenSetMiterLimit extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setMiterLimit(10);
    }
  }
}

export class PerformancePenGetMiterLimit extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getMiterLimit();
    }
  }
}

export class PerformancePenSetPathEffect extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let pathEffect = new drawing.PathEffect();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setPathEffect(pathEffect);
    }
  }
}

export class PerformancePenSetShadowLayer extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let effect = new drawing.ShadowLayer();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setShadowLayer(effect);
    }
  }
}

export class PerformancePenSetShaderEffect extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let effect = new drawing.ShaderEffect();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setShaderEffect(effect);
    }
  }
}

export class PerformancePenSetBlendMode extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setBlendMode(drawing.BlendMode.CLEAR);
    }
  }
}

export class PerformancePenSetDither extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setDither(true);
    }
  }
}

export class PerformancePenSetJoinStyler extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setJoinStyle(drawing.JoinStyle.MITER_JOIN);
    }
  }
}

export class PerformancePenGetJoinStyler extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getJoinStyle();
    }
  }
}

export class PerformancePenSetCapStyle extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setCapStyle(drawing.CapStyle.FLAT_CAP);
    }
  }
}

export class PerformancePenGetCapStyle extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getCapStyle();
    }
  }
}

export class PerformancePenGetWidth extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getWidth();
    }
  }
}

export class PerformancePenIsAntiAlias extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.isAntiAlias();
    }
  }
}

export class PerformancePenReset extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.reset();
    }
  }
}

export class PerformancePenGetFillPath extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let pathSrc = new drawing.Path();
    let pathDst = new drawing.Path();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.getFillPath(pathSrc, pathDst);
    }
  }
}

export class PerformancePenSetImageFilter extends TestBase {
  public constructor(styleType: number = StyleType.DRAW_STYLE_NONE) {
    super();
    this.styleType_ = styleType;
  }

  public OnTestPerformance(canvas: drawing.Canvas) {
    let pen = new drawing.Pen();
    let filter = new drawing.ImageFilter();
    this.StartPerformanceCaculate();
    for (let i = 0; i < this.testCount_; i++) {
      pen.setImageFilter(filter);
    }
  }
}